﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MobileIdeas.MobileTasks.SDK.DAL;
using MobileIdeas.MobileTasks.SDK.DAL.Repositories;
using MobileIdeas.MobileTasks.SDK.Common.Exceptions;

namespace MobileIdeas.MobileTasks.SDK.Services
{
    public class SecurityService
    {
        ISecurityRepository securityRepository;

        public SecurityService()
        {
            this.securityRepository = new SecurityRepository();
        }

        public List<Permission> Login(string username, string password, int companyId)
        {
            try
            {
                User user = this.securityRepository.GetUser(username, password, companyId);

                return this.securityRepository.GetUserPermissions(user.userId);
            }
            catch (DataAccessException ex)
            {
                return null;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
